/**
 * Version is the class containing a specific version of module archive.
 *  
 * @author Eric LEON
 * @version 1.0.0
 */
package models;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;

import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import play.db.jpa.Model;

import com.google.gson.annotations.Expose;

@Entity(name="tdVersion")
public class Version extends Model {
	
	/**
	 * The version string, can't be null. This is a free text field, no control is made
	 * on its content.
	 */
	@Column(nullable=false)

	@Expose
	public String version = "1.0";

	/**
	 * The flag indicating whether this version is the default one or not.
	 * Only one version should have this flag set for a given module.
	 */
	@Expose
	public Boolean isDefault = false;
	
	/**
	 * This is the original filename of the module archive.
	 */
	@Column(nullable=false)
    public String filename = null;

	/**
	 * This is a string indicating with which Play! framework version this module is compatible.
	 */
	@Column(nullable=false)
	@Expose
    public String matches = "1.0";
	
	/**
	 * The object creation date.
	 */
	public Date date = new Date();
    
	/**
	 * The embedded module archive content.
	 */
    @Lob
	@Column(nullable=false)
    public byte[] code = null;
    
    public Version() {
    }
    
    public Version(String version, Boolean isDefault, String matches, String filename, byte[] code) {
        this.version = version;
        this.isDefault = isDefault;
        this.matches = matches;
        this.filename = filename;
        this.code = code;
    }
    
	@Override
    public String toString() {
    	return this.version;
	}
}
